<?php

use Illuminate\Database\Seeder;
use App\Models\Article;
use Faker\Factory;

class ArticleTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
//                非模型工厂填充数据
        Article::truncate();
        $faker = Factory::create('zh_CN');

        $data = [];
        for($i=0;$i<1500;$i++){
            $data[] = [
                'table' => $faker->name,
                'cagetory' => $faker->unique()->phoneNumber,
                'originate' => $faker->unique()->email,
                'page_views' => mt_rand(5,10),
                'status' => mt_rand(1,2),
            ];
        }

        Article::insert($data);


        $res = Article::select('id')->get()->toArray();
        $len = count($res);
        for($i=1;$i<=$len;$i++){
            $data  = [
                'created_at'=>date("Y-m-d H:i:s", mt_rand(strtotime('2018-11-13'),'1545369765')),
                'updated_at'=>date("Y-m-d H:i:s", mt_rand(strtotime('2018-11-13'),'1545369765')),
            ];
            Article::where('id','=',$i)->update($data);
        }


    }
}

